package com.xuecheng.media.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xuecheng.media.mapper.provider.MediaProcessProvider;
import com.xuecheng.media.model.po.MediaProcess;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口ddddd
 * </p>
 *
 * @author itcast
 */
public interface MediaProcessMapper extends BaseMapper<MediaProcess> {
    /**
     * 根据分片参数查询待处理的媒资信息
     * @param shardingIndex 分片索引
     * @param shardingTotal 分片参数
     * @param total 查询总数
     * @return List<MediaProcess>
     */
    @SelectProvider(value = MediaProcessProvider.class,method = "selectListByShardIndex")
    List<MediaProcess> selectListByShardIndex(@Param("shardingIndex") Integer shardingIndex,
                                              @Param("shardingTotal") Integer shardingTotal,
                                                 @Param("total")Integer total);

    /**
     * 开启一个任务
     * @param id 任务id
     * @return 影响行数
     */
    @Update("UPDATE media_process m SET m.status = '4' " +
            "WHERE id = #{id} and (m.status = '3' or m.status = '1') and m.fail_count < 3")
    int startTask(@Param("id") Long id);
}
